import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/config/global_configs.dart';
import 'package:ls_work/init_page/webview_page.dart';
import 'package:ls_work/util/ext_utils.dart';

import '../res/colors.dart';
import '../res/gaps.dart';

void showPolicyDialog(BuildContext context,
    {
    Function()? onCancelClick,
    Function()? onApplyClick}) {
  showDialog(
      context: context,
      barrierDismissible:false,
      builder: (context) {
        return PopScope(child: Dialog(
          backgroundColor: Colors.transparent,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              SizedBox(
                height: 20,
              ),
              CommonText("隐私保护提示",
                  fontWeight: FontWeight.w500, textColor: Colours.text_dark),
              SizedBox(
                height: 10,
              ),
              Text.rich(TextSpan(
                  text: '感谢您使用数字康养app,我们非常重视您的个人信息和隐私保护，为了更好的保障您的个人权益，在您使用本产品前，请您阅读',
                  children: [
                    TextSpan(
                        text: '《服务协议》',
                        style: TextStyle(fontSize: 16,color: Colours.app_main,height: 1.6),
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            Go().push(WebViewPage(title: '服务协议', url: GlobalConfigs.agreenment));
                          }
                    ),
                    TextSpan(
                        text: '和',
                        style: TextStyle(fontSize: 16,color: Colors.black,height: 1.6)
                    ),
                    TextSpan(
                        text: '《隐私政策》',
                        style: TextStyle(fontSize: 16,color: Colours.app_main,height: 1.6),
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            Go().push(WebViewPage(title: '隐私政策', url: GlobalConfigs.privacy));
                          }
                    ),
                    TextSpan(
                        text: '的全部内容，同意并接受全部条款后开始使用我们的产品和服务。我们会样按照政策内容使用和保护您的个人信息，感谢您的信任。\n您点击同意即代表您已阅读并同意其相关内容。',
                        style: TextStyle(fontSize: 16,color: Colors.black,height: 1.6)
                    )
                  ]
              ),style: TextStyle(fontSize: 16,color: Colors.black,height: 1.6),),
              SizedBox(
                height: 24,
              ),
              Row(
                children: [
                  if (onCancelClick != null)
                    TextButton(
                      onPressed: () {
                        onCancelClick!();
                      },
                      child: CommonText('取消', textColor: Colours.text_dark),
                      style: ButtonStyle(
                          backgroundColor:
                          WidgetStateProperty.all(Color(0xffeeeeee)),
                          shape: WidgetStateProperty.all(StadiumBorder()),
                          minimumSize: WidgetStateProperty.all(
                              Size(double.infinity, 44))),
                    ).setWeight(1),
                  if (onApplyClick != null)
                    TextButton(
                      onPressed: () {
                        onApplyClick();
                      },
                      child: CommonText('确定', textColor: Colors.white),
                      style: ButtonStyle(
                          backgroundColor:
                          WidgetStateProperty.all(Colours.app_main),
                          shape: WidgetStateProperty.all(StadiumBorder()),
                          minimumSize: WidgetStateProperty.all(
                              Size(double.infinity, 44))),
                    ).setWeight(1)
                ].insertWidget(
                  SizedBox(
                    width: 15,
                  ),
                ),
              ),
              SizedBox(
                height: 16,
              )
            ],
          ).addToContainer(
              width: context.screenSize.width - 80,
              padding: EdgeInsets.symmetric(horizontal: 16),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: 8.borderRadius,
              )),
        ),canPop: false,);
      },);
}


void showPermissionDialog(BuildContext context,{required String msg,String? title,required Function() onApplyListener}){
  showDialog(context: context, builder: (context){
    return Dialog(
      backgroundColor: Colors.white,
      shape: RoundedRectangleBorder(borderRadius: 8.borderRadius),
      child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 12,),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            SizedBox(height: 16,),
            if(!title.isNullOrEmpty())
              ...[
                CommonText(title),
                const SizedBox(height: 12,),
                Gaps.dividerLine,
                const SizedBox(height: 12,)
              ],

            CommonText(msg),

            SizedBox(height: 12,),
            Gaps.dividerLine,
            // const SizedBox(height: 12,),
            Row(
              children: [
                TextButton(onPressed: (){
                  Go().pop();
                }, child: CommonText('取消',textColor: Colors.grey)).setWeight(1),
                TextButton(onPressed: (){
                  Go().pop();
                  onApplyListener();
                }, child: CommonText('确定',textColor: Colors.blue)).setWeight(1)

              ],
            )

          ],
        ),
      ),
    );
  });
}
